package com.Cfeng.XiaohuanChat.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.messaging.MessageSecurityMetadataSourceRegistry;
import org.springframework.security.config.annotation.web.socket.AbstractSecurityWebSocketMessageBrokerConfigurer;

/**
 * @author Cfeng
 * @date 2022/8/3
 * 消息安全的配置类，继承AbstractSecurityWebSocketMessageBrokerConfigurer
 * 完成消息路径的安全认证，允许跨域访问
 */

@Configuration
public class SocketSecurityConfig extends AbstractSecurityWebSocketMessageBrokerConfigurer {

    @Override
    protected void configureInbound(MessageSecurityMetadataSourceRegistry messages) {
        messages
                .simpDestMatchers("/**").authenticated() //所有路径都需要登录才能访问
                .anyMessage().authenticated();  //所有的消息都需要登录才能查看
    }

    @Override
    protected boolean sameOriginDisabled() {
        return true;  //允许跨域访问
    }
}
